<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-list-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label  layui-label-jy">配送计划单号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="code" placeholder="多个用空格或逗号隔开" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label  layui-label-jy">收货店铺</label>
                    <div class="layui-input-inline">
                        <select lay-filter="shop_id_rec" name="shop_id_rec" lay-search>
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label layui-label-jy">需求配送日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="distribution_time" class="layui-input " id="fy2Time"
                               placeholder="yyyy-MM-dd">
                    </div>
                </div>

                <div class="layui-inline">
                    <button style="display:none" class="down" lay-submit="" lay-filter="LAY-list-down">下载</button>
                    <button class="layui-btn layuiadmin-btn-useradmin search" lay-submit lay-filter="LAY-list-search">
                        搜索
                    </button>
                    <button class="layui-btn layui-btn-primary reset">
                        重置
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-list" lay-filter="LAY-list"></table>
            <!-- 行内工具  1 2可编辑-->
            <script type="text/html" id="LAY-list-toolbar">
                {{# var type=2; if(d.status==0){ type=1;   }}
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="Distribution/create/id={{d.id}}">编辑</a>
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="audit">提审</a>
                {{# }else if(d.status==1){ }}
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-href="Distribution/detail/id={{d.id}}/type=2">审核</a>
                {{# } }}
                <a class="layui-btn layui-btn-normal layui-btn-xs"
                   lay-href="Distribution/detail/id={{d.id}}">详情</a>
                <!--<a class="layui-btn layui-btn-normal layui-btn-xs jy-act" jy-data="{}" jy-href="/index/Purchasemanage/createAuto?code={{d.code}}">生成</a>-->
            </script>
            <!-- 头部工具栏 -->
            <script type="text/html" id="toolbar">
                <div class="layui-btn-group fl layui-btn-group-jy">
                    <a lay-href="Distribution/create"
                       class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine">&nbsp;新增</a>
                    <a lay-event="export" href="javascript:;"
                       class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-download-circle">&nbsp;导出</a>
                </div>
            </script>


        </div>
    </div>
</div>

<script>
    layui.use(['admin', 'table', 'form', 'toolJ', 'laydate'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , laydate = layui.laydate
            , toolJ = layui.toolJ
            , form = layui.form;
        laydate.render({
            elem: '#fy1Time'
        });
        laydate.render({
            elem: '#fy2Time'
        });
        table.render({
            elem: '#LAY-list'
            , url: '/index/Distribution/index'
            , toolbar: '#toolbar'
            , defaultToolbar: ['filter']
            , cellMinWidth: 80
            , cols: [[
                {field: 'code', title: '配送计划单号', width: 90}
                , {field: 'sku_num', title: 'SKU'}
                , {field: 'company_str_out', title: '发货公司'}
                , {field: 'warehouse_str_out', title: '发货仓库'}
                , {field: 'warehouse_str_rec', title: '收货仓'}
                , {field: 'shop_str_rec', title: '收货店铺'}
                , {field: 'country_str_rec', title: '国家'}
                , {field: 'distribution_time', title: '需求配送日期'}
                , {field: 'type_status', title: '类型'}
                , {field: 'operator', title: '创建人'}
                , {field: 'ctime', title: '创建时间'}
                , {field: 'auditor', title: '审核人'}
                , {field: 'audit_time', title: '审核时间'}
                , {field: 'status_text', title: '状态'}
                , {title: '操作', width:150,align: 'center', fixed: 'right', toolbar: '#LAY-list-toolbar'}
            ]]
            , page: true
            , limit: 10
            ,text:{none: '暂无相关数据!' }
        });

        var shop = layui.data(layui.setter.tableName).shop;
        var selectHtml = '';
        for (var i in shop) {
            selectHtml += '<option value="' + i + '">' + shop[i] + '</option>';
        }
        $("select[name='shop_id_rec']").append(selectHtml);
        form.render(null, 'LAY-list-form');
        //监听头部工具栏 导出
        layui.table.on('toolbar(LAY-list)', function (obj) {
            switch (obj.event) {
                case 'export':
                    $('.down').click();
                    break;
            }
        });
         table.on('tool(LAY-list)', function(obj){
            var param={"id":obj.data.id,"status":1};
            if(obj.event){
                 toolJ.ajax({"data": param, "url": "/index/Distribution/audithandle"});
                 $('.search').click();
            }
        });

    });
</script>